<?php
namespace Avalanche\Model;

use Avalanche\Model;

/**
 *
 */
class ResponseModel extends Model {

    /**
     * @var string
     */
    protected $protocol = 'HTTP/1.0';

    /**
     * @var int
     */
    protected $code = 200;

    /**
     * @var string
     */
    protected $msg = 'OK';

    /**
     * @var array
     */
    protected $headers = array();

    /**
     * @var stirng
     */
    protected $body = '';

    /**
     * @param string $body
     */
    public function setBody($body) {
        $this->body = $body;
    }

    /**
     * Get response body
     *
     * @return string
     */
    public function get() {
        $response = $this->protocol . ' ' . $this->code . ' ' . $this->msg . CRLF;
        foreach ($this->headers as $name => $value) {
            $response .= $name . ': ' . $value . CRLF;
        }
        $response .= CRLF;
        $response .= $this->body;

        return $response;
    }

    /**
     * @param string $name
     * @param string $value
     */
    public function setHeader($name, $value)
    {
        $this->headers[$name] = $value;
    }

}